<?php
/**
* @version		$Id: mod_youtubelist.php 1.0 $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

require_once('BBParser.php');

$maxVideos = 5;
$linkvideo = "http://www.youtube.com/v/";
/*$linkvideo = "http://localhost/thaoduocankhang.com/media/";*/

// get params set by user
$numVideos = $params->get('vdnum');
$vdWidth = $params->get('vdwidth');
$vdHeight = $params->get('vdheight');
$vdDescription = $params->get('vdDescr');
$video1 = $params->get('video1');

$document =& JFactory::getDocument();

$style = "#videoDiv {";
$style .= "margin-right: 3px;";
$style .= "}";
$style .= "#videoInfo {";
$style .= "margin-left: 3px;";
$style .= "}";
$document->addStyleDeclaration($style);

//Add Google JavaScripts
$document->addScript( 'http://www.google.com/jsapi' );

$jstag = "<script type=\"text/javascript\">";
$jstag .= "google.load(\"swfobject\", \"2.1\");";
$jstag .= "</script>";
$document->addCustomTag($jstag);

$jsmain = "<script type=\"text/javascript\">";
$jsmain .= "function updateHTML(elmId, value) {";
$jsmain .= "document.getElementById(elmId).innerHTML = value;";
$jsmain .= "}";

$jsmain .= "function loadVideo() {";
$jsmain .= "var selectBox = document.getElementById(\"videoSelection\");";
$jsmain .= "var videoID = selectBox.options[selectBox.selectedIndex].value;";

$jsmain .= "if(ytplayer) {";
$jsmain .= "ytplayer.loadVideoById(videoID);";
$jsmain .= "}";
$jsmain .= "}";

$jsmain .= "function onPlayerError(errorCode) {";
$jsmain .= "alert(\"An error occured of type:\" + errorCode);";
$jsmain .= "}";

$jsmain .= "function onYouTubePlayerReady(playerId) {";
$jsmain .= "ytplayer = document.getElementById(\"ytPlayer\");";
$jsmain .= "ytplayer.addEventListener(\"onError\", \"onPlayerError\");";
$jsmain .= "}";

$jsmain .= "function loadPlayer() {";
$jsmain .= "var videoID = \"$video1\"; ";
$jsmain .= "var params = { allowScriptAccess: \"always\" };";
$jsmain .= "var atts = { id: \"ytPlayer\" };";
$jsmain .= "swfobject.embedSWF(\"$linkvideo\" + videoID +";
$jsmain .= "\"&enablejsapi=1&playerapiid=player1\",";
$jsmain .= "\"videoDiv\", \"$vdWidth\", \"$vdHeight\", \"8\", null, null, params, atts);";
$jsmain .= "}";

$jsmain .= "function _run() {";
$jsmain .= "loadPlayer();";
$jsmain .= "}";

$jsmain .= "google.setOnLoadCallback(_run);";
$jsmain .= "</script>";
$document->addCustomTag($jsmain);

echo '<table>';
echo '    <tr>';
echo '    <td style="height:150"><div id="videoDiv">Loading...</div></td></tr>';
echo '    <tr><td valign="top">';
echo '      <div id="videoControls">';
//echo '        <p style="margin:0px; padding:2px">' . bb2html($vdDescription) .'</p>';
//echo '        <p style="margin:0px; padding:2px">Chọn video clip:</p>';
echo '        <select id="videoSelection" onchange="loadVideo();" size="5" style="width:280px; height:50px; overflow:hidden">';
for($i=1 ; $i <= $numVideos ; $i++)
{
	if($i == 1 )
		echo '<option value="' . $params->get( 'video' . $i ) . '" selected>' . $params->get( 'video' . $i  . 'desc' ) . '</option>';
	else
		echo '<option value="' . $params->get( 'video' . $i ) . '">' . $params->get( 'video' . $i  . 'desc' ) . '</option>';
}
echo '        </select>';
echo '      </div>';
echo '    </td></tr>';
echo '    </table>';


?>

